package site.shenjie.zuul.demo.filter;

import com.alibaba.fastjson.JSONObject;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.apache.commons.lang.StringUtils;
import site.shenjie.zuul.demo.tool.IpUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 沈杰
 * 2020-7-28 14:53:53
 * 拦截器：二级拦截器
 */
public class TwoLevelFilter extends ZuulFilter {
    @Override
    public String filterType() {
        return "pre";
    }

    @Override
    public int filterOrder() {
        return 2;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        System.out.println("正在二级拦截...");
        RequestContext ctx = RequestContext.getCurrentContext();
        String info = String.valueOf(ctx.get("sendToTwoLevel"));
        System.out.println("来自一级拦截器的消息是：" + info);
        // 放行
        ctx.setSendZuulResponse(true);
        System.out.println("已允许通过...");
        return null;
    }
}
